package com.lidong.lowcode.model.model.impl;

import com.lidong.lowcode.base.component.FunctionMenu;
import com.lidong.lowcode.base.domain.MenuVO;
import com.lidong.lowcode.model.domain.modelconst.ModelConst;
import com.lidong.toolkit.constant.LogConst;
import com.lidong.toolkit.constant.StringConst;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author LiDong
 * @version 1.0.0
 * @createTime 5/2/2022 10:48 AM
 */
@Component
public class ModelFunctionMenu implements FunctionMenu {

    private static final Logger logger = LoggerFactory.getLogger(ModelFunctionMenu.class);

    @Override
    public String moduleName() {
        return ModelConst.MODULE_NAME;
    }

    @Override
    public String moduleCode() {
        return ModelConst.MODULE_NAME;
    }

    @Override
    public List<MenuVO> getMenuList() {
        List<MenuVO> menuList = new ArrayList<>();

        MenuVO menu = new MenuVO();
        menu.setId(ModelConst.MODEL_MENU_CODE);
        menu.setParentId(StringConst.ZERO);
        menu.setTitle(ModelConst.MODULE_NAME);
        menu.setUrl("/back/model");

        List<MenuVO> children = new ArrayList<>();
        MenuVO datasourceMenuVO = new MenuVO();
        datasourceMenuVO.setId(ModelConst.DATASOURCE_MENU_CODE);
        datasourceMenuVO.setParentId(ModelConst.MODEL_MENU_CODE);
        datasourceMenuVO.setTitle(ModelConst.DATASOURCE_MENU_NAME);
        datasourceMenuVO.setUrl("/back/model/datasource");

        MenuVO modelMenuVO = new MenuVO();
        modelMenuVO.setId(ModelConst.MODEL_MENU_CODE);
        modelMenuVO.setParentId(ModelConst.MODEL_MENU_CODE);
        modelMenuVO.setTitle(ModelConst.MODEL_MENU_NAME);
        modelMenuVO.setUrl("/back/model/model");

        children.add(datasourceMenuVO);
        children.add(modelMenuVO);
        menu.setChildren(children);
        menuList.add(menu);
        logger.info(LogConst.LOG_SUCCESS_PREFIX + "lowcode-model 菜单注册");
        return menuList;
    }
}
